package cn.wolfcode.trip.base.domain;


import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 地区
 */
@Setter
@Getter
public class Region extends BaseDomain{

    public static final int STATE_NOMAL = 0;//普通
    public static final int STATE_HOT = 1;//推荐

    //名称
    private String name;
    //上级地区
    private Region parent;
    //状态
    private int state;

    public Map toTreeViewMap(){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("text",name);
        map.put("lazyLoad",true);//作用是显示+号
        //判断是否是推荐状态
        if(state == STATE_HOT){
            map.put("tags",new String[]{"推荐"});
        }
        return map;
    }

    //把当前对象信息转发JSON返回,当前对象中多了个属性,名称叫json
    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("state", state);
        if(parent!=null){
            map.put("parentId", parent.getId());
            map.put("parentName", parent.getName());
        }
        return JSONUtil.toJSONString(map);
    }

}